package elearning.controller.admin.regist;

import java.util.logging.Logger;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.controller.validator.Validators;
import org.slim3.util.BeanUtil;

import elearning.model.Exam;
import elearning.service.ElearningService;

public class InsertController extends Controller {

	@SuppressWarnings("unused")
	private static final Logger logger = Logger
			.getLogger(InsertController.class.getName());

	private ElearningService service = new ElearningService();

	@Override
	public Navigation run() {
		if (!validate()) {
			return forward("create");
		}
		Exam exam = new Exam();
		BeanUtil.copy(request, exam);
		service.insert(exam);
		return redirect(basePath);
	}

	private boolean validate() {
		Validators v = new Validators(request);
		v.add("examName", v.required());
		return v.validate();
	}
}
